package com.bistu.xiong.tulingrobotchat.frags.account;

import android.content.Context;
import android.widget.EditText;

import com.bistu.xiong.common.app.PresenterFragment;
import com.bistu.xiong.factory.presenter.accout.LoginContract;
import com.bistu.xiong.factory.presenter.accout.LoginPresenter;
import com.bistu.xiong.tulingrobotchat.R;
import com.bistu.xiong.tulingrobotchat.activities.MainActivity;


import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by XiongXiaoJun on 2017/12/04.
 */

public class LoginFragment extends PresenterFragment<LoginContract.Presenter> implements LoginContract.View{
    @BindView(R.id.edit_password)
    EditText editPassword;
    @BindView(R.id.edit_phone)
    EditText editPhone;

    private AccountTrigger mAccountTrigger;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mAccountTrigger = (AccountTrigger)context;
    }

    @Override
    protected int getContentLayoutId() {
        return R.layout.fragment_login;
    }

    @Override
    public void loginSuccess() {
        //登录成功 跳转到主页面
        MainActivity.show(getContext());
        getActivity().finish();
    }

    @Override
    public void showLoading() {
        super.showLoading();

    }

    @Override
    protected LoginPresenter initPresenter() {
        return new LoginPresenter(this);
    }

    /**
     * 切换当前页面为注册页面
     */
    @OnClick(R.id.txt_go_register)
    void onShowRegisterClick(){
        //让AccountActivity进行界面切换
        mAccountTrigger.triggerView();
    }

    /**
     * 提交用户登录信息 进行登录操作
     */
    @OnClick(R.id.btn_submit)
    void onSubmitClick(){
        String phone = editPhone.getText().toString();
        String password = editPassword.getText().toString();
        //调用P层进行注册
        mPresenter.login(phone,password);
    }

}
